﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Globalization;
using Microsoft.Practices.Unity;
using Vit.Common.Extensions;
using Vit.Common.Providers;

namespace Vit.Common.Helpers
{
    public class Locale
    {
        public static string GetString(string assemblyName, string resourceName)
        {
            return Unity.Current.ResolveAny<ILocalizationProvider>().ForEach<ILocalizationProvider, string>(p => p.GetString(assemblyName, resourceName), (r) => !string.IsNullOrWhiteSpace(r));
        }

        public static string GetString<T>(string resourceName)
        {
            return Unity.Current.ResolveAny<ILocalizationProvider>().ForEach<ILocalizationProvider, string>(p => p.GetString<T>(resourceName), (r) => !string.IsNullOrWhiteSpace(r));
        }

        public static string GetString(object obj, string resourceName)
        {
            return Unity.Current.ResolveAny<ILocalizationProvider>().ForEach<ILocalizationProvider, string>(p => p.GetString(obj, resourceName), (r) => !string.IsNullOrWhiteSpace(r));
        }

        public static string GetString(Type type, string resourceName)
        {
            return Unity.Current.ResolveAny<ILocalizationProvider>().ForEach<ILocalizationProvider, string>(p => p.GetString(type, resourceName), (r) => !string.IsNullOrWhiteSpace(r));
        }

        public static string GetString(string assemblyName, string resourceName, string cultureInfo)
        {
            return Unity.Current.ResolveAny<ILocalizationProvider>().ForEach<ILocalizationProvider, string>(p => p.GetString(assemblyName, resourceName, cultureInfo), (r) => !string.IsNullOrWhiteSpace(r));
        }

        public static string GetString<T>(string resourceName, string cultureInfo)
        {
            return Unity.Current.ResolveAny<ILocalizationProvider>().ForEach<ILocalizationProvider, string>(p => p.GetString<T>(resourceName, cultureInfo), (r) => !string.IsNullOrWhiteSpace(r));
        }

        public static string GetString(object obj, string resourceName, string cultureInfo)
        {
            return Unity.Current.ResolveAny<ILocalizationProvider>().ForEach<ILocalizationProvider, string>(p => p.GetString(obj, resourceName, cultureInfo), (r) => !string.IsNullOrWhiteSpace(r));
        }

        public static string GetString(Type type, string resourceName, string cultureInfo)
        {
            return Unity.Current.ResolveAny<ILocalizationProvider>().ForEach<ILocalizationProvider, string>(p => p.GetString(type, resourceName, cultureInfo), (r) => !string.IsNullOrWhiteSpace(r));
        }
    }
}
